package org.eddm.ui.panel;


import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;

import org.flexdock.view.View;


/**
 * @author Andre Luiz Reis
 */
public class ProblemsPanel {
	
	public ProblemsPanel(){
		
		
	}
	public View createView(String id, String text) {
		View view = new View(id, text);
		//view.addAction(CLOSE_ACTION);
		view.addAction("pin");

		JPanel p = new JPanel();
		p.setLayout(new BorderLayout());
		//p.setBackground(Color.WHITE);
		p.setBorder(new LineBorder(Color.GRAY, 1));
		// Campo de texto
		JTextArea jTextArea = new JTextArea();
		jTextArea.setLineWrap(true);
				
		
		// Painel com scroll
		JScrollPane jScrollPane = new JScrollPane(jTextArea);
		
		// Adiciona o painel com scroll no painel principal
		p.add(jScrollPane, BorderLayout.CENTER);
		
		//********************************
		List<String> strSVGList = getSVGList();
		for( int i = 0; i < strSVGList.size(); i++ ){			
				jTextArea.append(strSVGList.get(i) + "\n");				
						
		}//for
		
		//********************************
		
		view.setContentPane(p);
		return view;
	}
	
	/**
	 * @name getSVGList
	 * @return List<String>
	 */
	public List<String> getSVGList(){
		
		java.io.File currentDir = new java.io.File("");
		String absolutPath = currentDir.getAbsolutePath();
		
		File folder = new File(absolutPath + "/bin/svgs/");
		File[] fList = folder.listFiles();
		
		List<String> strSVGList = new ArrayList<String>();
		
		for( int i = 0; i < fList.length; i++ ){			
			if (fList[i].getName().toLowerCase().endsWith(".svg") ){
				strSVGList.add( fList[i].getName() );				
			}//if			
		}//for
		
		return strSVGList;
	
	}

}
